package graphics.objects;
import java.io.Serializable;

import physics.Body;
import physics.joints.Joint;
import tools.Point;
import tools.id.IdObject;
import graphics.system.Color;
import graphics.system.Node;
/**
 * Represents an abstract object in the graphics engine. This is the connection between graphics and physics. Graphics objects can either be dynamic (meaning their position/rotation is determined by something not from the physical world), connected to a body or connected to a joint. Which of these modes is used is stated in the gSync class. (probably invent a better name for that one :) )
 * 
 * @author yonarw
 * 
 */
public abstract class GraphicsObject implements Serializable, IdObject {
	public int id = IdObject.DEFAULTID;
	public Color color;
	/*
	 * used to draw shadows and "glow"
	 */
	public Color glowColor;
	public Node node;
	public boolean iseffect;
	public boolean islight;
	public boolean isshape;
	public GraphicsObject(Point pos, float angle, Color color) {
		this.node = new Node(pos, angle);
		this.node.scale = new Point(1, 1);
		this.color = color;
		iseffect = false;
		glowColor = new Color(0, 0, 0, 0.5f);
	}
	public GraphicsObject() {
	}
	public void draw() {
	}
	public void drawDebug() {
		draw();
	}
	public void drawShadow(Point lightPos, float radius) {
	}
	public void drawWarp() {
	}
	public void drawSpec(Point lightPos, float lradius, Color lc, float zoom) {
	}
	public void delete() {
	}
	public void syncToBody(Body b, Point offset, float angle) {
		offset = offset.rotate(b.apos);
		node.moveAbs(b.pos.add(offset));
		node.rotateAbs(b.apos);
		node.apos = b.apos + angle;
	}
	public void syncToJoint(Joint j) {
	}
	@Override
	public int getId() {
		return id;
	}
	@Override
	public void setId(int id) {
		this.id = id;
	}
	@Override
	public void setIndexInList(int i) {
	}
	public void drawGlow() {
	}
	public String toFileString() {
		String s = node.pos.toFileString() + "/" + node.apos + "/" + node.zpos + "/" + node.scale.toFileString() + "/" + color.toFileString() + "/" + glowColor.toFileString();
		return s;
	}
	/**
	 * 
	 * @param s
	 *            filestring
	 * @returns number of next element for parsing in child classes
	 */
	public int fromFileString(String s) {
		String l[] = s.split("/");
		node.pos = Point.valueOf(l[0]);
		node.apos = Float.valueOf(l[1]);
		node.zpos = Byte.valueOf(l[2]);
		node.scale = Point.valueOf(l[3]);
		color = Color.fromFileString(l[4]);
		glowColor = Color.fromFileString(l[5]);
		return 5;
	}
}
